//
//  NSObject+HDRepairDetailManager.m
//  app
//
//  Created by D on 15/8/31.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HDRepairDetailManager.h"
#import "HDShouFeiXiagnXiModel.h"

@interface HDRepairDetailManager ()

@property (nonatomic,strong) JKHttpClient * jkHttp;
@property (nonatomic,strong) SNUniteUrl * uniteUrl;
@property (nonatomic,strong) NSMutableArray * array;

@end

@implementation  HDRepairDetailManager

+(HDRepairDetailManager *)shareManager
{
    AS_SINGLETON(HDRepairDetailManager, manager, {
        
        manager = [[HDRepairDetailManager alloc]init];
        manager.jkHttp = [[JKHttpClient alloc]init];
        manager.uniteUrl = [SNUniteUrl shareUniteUrl];
        manager.array = [NSMutableArray array];
        
    })
    return manager;
}

-(void)makeSureFinish:(HDRepairDetailResult *)result Params:(NSString *)params
{
    if ([self.jkHttp isRunning]) {
        return;
    }
    
    NSString * url = [NSString stringWithFormat:@"http://mylife114.com/android_oa/app_confirm_repair_apply?code=%@",params] ;
   
    
    [self.jkHttp get:url  result:^(JKResponse *resp) {
        
        if (resp.OK) {
            result.success = YES;
            
        }else if (resp.failure){
            result.failure = YES;
        }
        result.message = resp.message;
        [result invoke];
        
        
    }];

}


-(void)loadShoufeimingxiData:(HDShoufeimingxiResult *)result Params:(NSDictionary *)params
{
    if ([self.jkHttp isRunning]) {
        return;
    }
    
    
    
    NSString * url = @"http://mylife114.com/android_oa/info_repair_distribute_price_list";
    
    [self.jkHttp post:url params:params result:^(JKResponse *resp) {
        
        if (resp.OK) {
            result.success = YES;
            result.failure = NO;
            
            if ([resp.content[@"result"] isKindOfClass:NSArray.class] ) {
                result.dataSourceArray = [self shoufeimingxiDataSourceWithArray:resp.content[@"result"]];
            }
            result.message = resp.content[@"result"];
            
            
            
        } else {
            result.failure = YES;
            result.success = NO;
            result.message = resp.message;
        }
        [result invoke];
        
    }];

    

}


-(NSMutableArray*)shoufeimingxiDataSourceWithArray:(NSArray*)array
{
    
    [self.array removeAllObjects];
    
    for (int i = 0 ; i < array.count; i++) {
        NSDictionary * dict = [array objectAtIndex:i];
        HDShouFeiXiagnXiModel * model = [HDShouFeiXiagnXiModel modelWithDict:dict];
        [self.array addObject:model];
        
    }
    
    return self.array;
    
}


-(void)submitPingjiaData:(HDPingJiaResult *)result Params:(NSDictionary *)params
{
    if ([self.jkHttp isRunning]) {
        return;
    }
    
    
    
    NSString * url = @"http://mylife114.com/android_oa/app_get_repair_evaluation";
    
    [self.jkHttp post:url params:params result:^(JKResponse *resp) {
        
        if (resp.OK) {
            result.success = YES;
            result.failure = NO;
            
            result.message = resp.message;
            
            
            
        } else {
            result.failure = YES;
            result.success = NO;
            result.message = resp.message;
        }
        [result invoke];
        
    }];
    

}


@end





